package cn.hy;

import cn.hy.entity.Role;
import cn.hy.entity.User;
import cn.hy.repository.IRoleDao;
import cn.hy.repository.IUserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Slf4j
@SpringBootApplication
public class App  implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
    }


    @Resource
    private IUserDao userDao;

    @Resource
    private IRoleDao roleDao;

    @Override
    public void run(String... args) throws Exception {

//
//        Sort sort = Sort.by(Sort.Direction.DESC,"createTime");
//        PageRequest pageRequest = PageRequest.of(0, 10, sort);
//
//        Page<User> usersPage = userDao.findAll(pageRequest);
//        log.info("user info all :  {}",usersPage.iterator().next().toString());
//
//        Optional<User> optionalUser = userDao.findById(1L);
//        optionalUser.ifPresent(user -> log.info("user info  :  {}", user));
//
//        Page<Role> roleDaoAll = roleDao.findAll(pageRequest);
//        log.info("role info all :  {}",roleDaoAll.iterator().next().toString());

    }
}